<template>
	<view style="background-color: #fff; min-height: 100vh;">
		<u-swiper :list="list" height="350" :title="true" mode="none" @click="swiperClick"></u-swiper>
		<view class="bangdan">
			<view class="shuji" @click="bookCenter()">
				<image src="https://maomaotou.cn/emergency-study-manager/images/sjzx.png"></image>
				<text>书籍中心</text>
			</view>
			<view class="shuji" @click="videoCenter()">
				<image src="https://maomaotou.cn/emergency-study-manager/images/spzx.png"></image>
				<text>视频中心</text>
			</view>
			<view class="shuji" @click="testClick()">
				<image src="https://maomaotou.cn/emergency-study-manager/images/wddk.png"></image>
				<text>我的待考</text>
			</view>
			<view class="shuji" @click="codeClick()">
				<image src="https://maomaotou.cn/emergency-study-manager/images/wdlx.png"></image>
				<text>我的练习</text>
			</view>
		</view>
		<view class="study">
			<view class="study-left" @click="weeklyClick(0)">
				<text>每周一学</text>
				<image src="https://maomaotou.cn/emergency-study-manager/images/mzyx.png" mode="widthFix"></image>
			</view>
			<view class="study-right">
				<view class="study-right-top" @click="weeklyClick(1)">
					<text>每月一课</text>
				</view>
				<view class="study-right-top" @click="oneExamClick()">
					<text>每季一考</text>
				</view>
			</view>
		</view>
		<view class="focusOn">
			<view class="focusOn-title">
				<text>重点关注</text>
				<!-- <text class="more">查看更多></text> -->
			</view>
			<view class="focusOn-content">
				<view class="focusOn-content-item" v-for="(item,index) in focusList" :key="index" @click="focusClick(item)">
					<view class="focusOn-content-item-img">
						<u-image width="100%" height="200rpx" :src="item.imageUrl" mode="widthFix"></u-image>
					</view>
					<text>{{item.title}}</text>
				</view>
				
			</view>
		</view>
		<view class="focusOn">
			<view class="focusOn-title">
				<text>书籍中心</text>
				<!-- <text class="more">查看更多></text> -->
			</view>
			<view class="focusOn-content">
				<view class="focusOn-content-item" style="height: 200rpx;" v-for="(item,index) in booksCentet" :key="index" @click="booksLink(item)">
					<view class="focusOn-content-item-img">
						<u-image width="100%" height="200rpx" :src="item.icon" mode="widthFix"></u-image>
					</view>
				</view>
			</view>
		</view>
		<view class="focusOn">
			<view class="focusOn-title">
				<text>视频中心</text>
				<!-- <text class="more">查看更多></text> -->
			</view>
			<view class="focusOn-content">
				<view class="focusOn-content-item" style="height: 200rpx;" v-for="(item,index) in videoCentet" :key="index" @click="booksLink(item)">
					<view class="focusOn-content-item-img">
						<u-image width="100%" height="200rpx" :src="item.icon" mode="widthFix"></u-image>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {banners} from '../../api/api.js'
	export default {
		data() {
			return {
				list: [],
				focusList: [],
				booksCentet: [
					{
						icon: 'https://maomaotou.cn/emergency-study-manager/images/flfg.png',
						type: 0,
						module: 0,
						title: '法律法规'
					},
					{
						icon: 'https://maomaotou.cn/emergency-study-manager/images/bzgf.png',
						type: 0,
						module: 1,
						title: '标准规范'
					},
					{
						icon: 'https://maomaotou.cn/emergency-study-manager/images/gzzd.png',
						type: 0,
						module: 2,
						title: '规章制度'
					},
					{
						icon: 'https://maomaotou.cn/emergency-study-manager/images/yzyh.png',
						type: 0,
						module: 3,
						title: '应知应会'
					}
				],
				videoCentet: [
					{
						icon: 'https://maomaotou.cn/emergency-study-manager/images/aqwdy.png',
						type: 1,
						module: 0,
						title: '安全微电影'
					},
					{
						icon: 'https://maomaotou.cn/emergency-study-manager/images/xbzdaq.png',
						type: 1,
						module: 1,
						title: '小班组大安全'
					},
					{
						icon: 'https://maomaotou.cn/emergency-study-manager/images/jsjy.png',
						type: 1,
						module: 2,
						title: '警示教育'
					},
					{
						icon: 'https://maomaotou.cn/emergency-study-manager/images/jpkc.png',
						type: 1,
						module: 3,
						title: '精品课程'
					}
				]
			}
		},
		onShow() {
			
		},
		onLoad() {
			
		},
		mounted() {
			this.getBanner()
			this.getFocus()
		},
		methods: {
			
			// 书籍中心和视频中心
			booksLink(item){
				// uni.navigateTo({
				// 	url:`../detail/detail?title=${item.name}&id=${item.id}`
				// })
				uni.navigateTo({
					url: `/pages/bookVideoList/bookVideoList?type=${item.type}&module=${item.module}&title=${item.title}`
				})
			},
			// 每周一学/一课
			weeklyClick(type){
				uni.navigateTo({
					url: `/pages/weekly/weekly?type=${type}`
				})
			},
			// 每季一考
			oneExamClick(){
				uni.navigateTo({
					url: '/pages/oneExam/oneExam'
				})
			},
			// banner跳转
			swiperClick(index){
				// uni.navigateTo({
				// 	url: `/pages/webView/webView?linkUrl=${this.list[index].linkUrl}&title=${this.list[index].title}`
				// })
				console.log(this.list[index].id)
				uni.navigateTo({
					url: `/pages/newsDetail/newsDetail?id=${this.list[index].id}`
				})
			},
			focusClick(item){
				// uni.navigateTo({
				// 	url: `/pages/webView/webView?linkUrl=${item.linkUrl}&title=${item.title}`
				// })
				uni.navigateTo({
					url: `/pages/newsDetail/newsDetail?id=${item.id}`
				})
			},
			// 获取banner---滚动资讯
			getBanner(){
				banners({page: 1,size: 20,type: 0}).then(resp=>{
					resp.content.forEach(item=>{
						item.image = item.imageUrl
					})
					this.list = resp.content
				})
			},
			// 获取重点关注
			getFocus(){
				banners({page: 1,size: 20,type: 1}).then(resp=>{
					this.focusList = resp.content
				})
			},
			// 书籍中心
			bookCenter(){
				uni.navigateTo({
					url: `/pages/bookCenter/bookCenter`
				})
			},
			// 视频中心
			videoCenter(){
				uni.navigateTo({
					url: `/pages/videoCenter/videoCenter`
				})
			},
			// 我得待考
			testClick(){
				uni.switchTab({
					url: `/pages/test/test`
				})
			},
			// 我得联系
			codeClick(){
				uni.switchTab({
					url: `/pages/code/code`
				})
			},
		}
	}
</script>

<style>
	/* page不能写带scope的style标签中，否则无效 */
	page {
		background-color: rgb(240, 240, 240);
	}
</style>

<style lang="scss" scoped>
	.bangdan{
		padding: 50rpx 30rpx;
		display: flex;
		justify-content: space-between;
		.shuji{
			display: flex;
			flex-wrap: wrap;
			justify-content: center;
			image{
				width: 100rpx;
				height: 100rpx;
			}
			text{
				padding-top: 20rpx;
				font-size: 24rpx;
			}
		}
	}
	.study{
		height: 380rpx;
		width: 100%;
		display: flex;
		justify-content: space-between;
		font-size: 32rpx;
		color: #000;
		&-left{
			height: 380rpx;
			width: 49%;
			border-radius: 6rpx;
			background-color: #ffe7c4;
			position: relative;
			text{
				position: absolute;
				left: 20rpx;
				top: 30rpx;
			}
			image{
				position: absolute;
				right: 20rpx;
				bottom: 20rpx;
				width: 50%;
			}
		}
		&-right{
			height: 380rpx;
			width: 48%;
			display: flex;
			flex-wrap: wrap;
			&-top{
				width: 100%;
				height: 180rpx;
				background-color: #b4bffa;
				border-radius: 10rpx;
				background-image: url(https://maomaotou.cn/emergency-study-manager/images/myyk.png);
				background-repeat: no-repeat;
				background-position: 90% 80%;
				background-size: 30%;
				position: relative;
				text{
					position: absolute;
					left: 20rpx;
					top: 20rpx;
				}
				&:last-child{
					margin-top: 20rpx;
					background-color: #95d8fb;
					background-image: url(https://maomaotou.cn/emergency-study-manager/images/mjyk.png);
					background-repeat: no-repeat;
					background-position: 90% 80%;
					background-size: 30%;
				}
			}
		}
	}
	.focusOn{
		padding: 20rpx 20rpx 0 20rpx;
		&-title{
			height: 50rpx;
			width: 100%;
			display: flex;
			justify-content: space-between;
			align-items: center;
			color: #000;
			text{
				font-size: 30rpx;
			}
			.more{
				font-size: 20rpx !important;
				opacity: 0.4;
			}
		}
		&-content{
			display: flex;
			flex-wrap: wrap;
			justify-content: space-between;
			&-item{
				background-color: #f0f0f0;
				border-radius: 10rpx;
				overflow: hidden;
				height: 300rpx;
				width: 48.5%;
				margin-top: 20rpx;
				&-img{
					height: 200rpx;
					overflow: hidden;
				}
				text{
					padding: 10rpx;
					height: 80rpx;
					width: 100%;
					display: -webkit-box;
					-webkit-box-orient: vertical;
					-webkit-line-clamp: 2;
					overflow: hidden;
					text-overflow: ellipsis;
					font-size: 26rpx;
					text-align: center;
					line-height: 35rpx;
				}
			}
		}
	}
</style>